home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Scope / Scope Disk #010 (199x)(Scope PD)(US)[WB].zip / Scope Disk #010 (199x)(Scope PD)(US)[WB].adf / BlitLab3 / blitlab.c < prev    next >
C/C++ Source or Header  |  1988-05-14  |  6KB  |  256 lines

  1. /*
  2.  *   This is the main routine from BlitLab.
  3.  */
  4. #include "structures.h"
  5. /*
  6.  *   Here are all the globals we use.  (Yuck!  Globals!)
  7.  */
  8. struct Window *mywindow ;
  9. struct GfxBase *GfxBase ;
  10. struct IntuitionBase *IntuitionBase ;
  11. struct RastPort *myrp ;
  12. char strings[900] ;
  13. char *bufarr[MAXGADG] ;
  14. long gvals[MAXGADG] ;
  15. struct Gadget *gadgets[MAXGADG] ;
  16. char errorbuf[140] ;
  17. short *realbits ;
  18. struct blitregs blitregs ;
  19. int custscreen ;
  20. /*
  21.  *   Externals we use:
  22.  */
  23. extern int blitsafe() ;
  24. extern int doblit() ;
  25. /*
  26.  *   Some statics to this module.
  27.  */
  28. static int updatethem ;
  29. /*
  30.  *   Errors go through here.  Currently, we write to the CLI window.
  31.  *   Later, we will write to the title bar of the window.
  32.  */
  33. error(s)
  34. char *s ;
  35. {
  36.    if (mywindow == NULL || *s == '!')
  37.       printf("blitlab: %s\n", s) ;
  38.    else {
  39.       SetWindowTitles(mywindow, s, -1L) ;
  40.    }
  41.    if (*s == '!')
  42.       cleanup() ;
  43. }
  44. /*
  45.  *   This routine handles a gadget selection.
  46.  */
  47. handlegadget(gp)
  48. register struct Gadget *gp ;
  49. {
  50.    static int gocount = 0 ;
  51.  
  52.    if (bufarr[gp->GadgetID] == NULL)
  53.    switch(gp->GadgetID) {
  54.       case GDGPNTREG:
  55.       case GDGLINE:
  56.       case GDGDESC:
  57.       case GDGFCI:
  58.       case GDGIFE:
  59.       case GDGEFE:
  60.       case GDGUSEA:
  61.       case GDGUSEB:
  62.       case GDGUSEC:
  63.       case GDGUSED:
  64.       case GDGOVF:
  65.       case GDGSIGN:
  66.       case GDGSIM:
  67.          flipgadg(gp->GadgetID) ;
  68.          break ;
  69.       case GDGCALC:
  70.          parseall() ;
  71.          updatethem = 0 ;
  72.          if (blitsafe()) {
  73.             error("Blit safe.") ;
  74.          } else {
  75.             error("Blit unsafe.") ;
  76.          }
  77.          break ;
  78.       case GDGSETUP:
  79.          setupline() ;
  80.          parseall() ;
  81.          break ;
  82.       case GDGGO:
  83.          gocount += 2 ;
  84.          parseall() ;
  85.          updatethem = 0 ;
  86.          if (!blitsafe() && gocount < 3) {
  87.             error("Blit unsafe---hit again to override") ;
  88.          } else {
  89.             if (doblit())
  90.                error("Zero flag SET") ;
  91.             else
  92.                error("Zero flag CLEAR") ;
  93.             updatebits() ;
  94.          }
  95.          break ;
  96.       case GDGUNDO:
  97.          undobits() ;
  98.          break ;
  99.       default:
  100.          error("! bad value in gadget switch") ;
  101.          break ;
  102.    }
  103.    if (gocount > 0)
  104.       gocount-- ;
  105. }
  106. /*
  107.  *   The main routine, no arguments.  Sets things up, and then goes
  108.  *   through the standard Intuition message loop.
  109.  *
  110.  *   It may look like I'm setting message to NULL and checking it and
  111.  *   everything all over, but that is so I can introduce interruptibility
  112.  *   into some operations later, if I choose.
  113.  */
  114. struct IntuiMessage *message = NULL ;
  115. main(argc, argv)
  116. int argc ;
  117. char *argv[] ;
  118. {
  119.    struct IntuiMessage *message = NULL ;
  120.    int x, y ;
  121.    int mousemoved = 0 ;
  122.    int getouttahere = 0 ;
  123.    int selectdown = 0 ;
  124.    int menudown = 0 ;
  125.    int bam ;
  126.    int ox, oy ;
  127.    char *p ;
  128.    int on ;
  129.  
  130.    while (argc > 1) {
  131.       argv++ ;
  132.       p = *argv ;
  133.       if (*p == '-')
  134.          p++ ;
  135.       if (*p == 'c' || *p == 'C')
  136.          custscreen = 1 ;
  137.       else {
  138.          printf("%s\n", BANNER) ;
  139.          printf("Usage:  blitlab [-c]\n") ;
  140.          printf("   -c:  Open on custom screen\n") ;
  141.          cleanup() ;
  142.       }
  143.       argc-- ;
  144.    }
  145.    initialize() ;
  146.    while (1) {
  147.       mousemoved = 0 ;
  148.       bam = 0 ;
  149.       if (message == NULL)
  150.          WaitPort(mywindow->UserPort) ;
  151.       while (message || (message = 
  152.                        (struct IntuiMessage *)GetMsg(mywindow->UserPort))) {
  153.          x = message->MouseX ;
  154.          y = message->MouseY ;
  155.          if (message->Class == MOUSEMOVE) {
  156.             ReplyMsg(message) ;
  157.             message = NULL ;
  158.             mousemoved = 1 ;
  159.          } else {
  160.             if (message->Class == MOUSEBUTTONS) {
  161.                selectdown = (message->Code == SELECTDOWN) ;
  162.                menudown = (message->Code == MENUDOWN) ;
  163.                bam = 1 ;
  164.             } else if (message->Class == GADGETDOWN || 
  165.                        message->Class == GADGETUP) {
  166.                updatethem = 1 ;
  167.                handlegadget((struct Gadget *)(message->IAddress)) ;
  168.             } else if (message->Class == CLOSEWINDOW) {
  169.                getouttahere = 1 ;
  170.             } else
  171.                error("! undefined message class") ;
  172.             ReplyMsg(message) ;
  173.             message = NULL ;
  174.          }
  175.       }
  176.       if (getouttahere)
  177.          break ;
  178.       if (updatethem) {
  179.          parseall() ;
  180.          updatethem = 0 ;
  181.       }
  182.       x = (x - HBITSTART + 2) / 6 ;
  183.       y = (y - VBITSTART) / 3 ;
  184.       if (y < 32 && x < 96 && x >= 0 && y >= 0) {
  185.          if (gvals[GDGPNTREG]) {
  186.             if (bam) {
  187.                if (selectdown || menudown) {
  188.                   ox = x ;
  189.                   oy = y ;
  190.                   on = selectdown ;
  191.                } else {
  192.                   preg(ox, oy, x, y, on) ;
  193.                }
  194.             }
  195.          } else {
  196.             if (selectdown || menudown)
  197.                pdot(x, y, selectdown) ;
  198.          }
  199.          if (message != NULL || (message = 
  200.                (struct IntuiMessage *)GetMsg(mywindow->UserPort))) ;
  201.          else
  202.             updatepos(x, y) ;
  203.       }      
  204.    }
  205.    cleanup() ;
  206. }
  207. /*
  208.  *   This routine gives us a log file, if appropriate.
  209.  */
  210. char filename[120] ;
  211. FILE *openlogfile() {
  212.    char *p, *q ;
  213.    FILE *f ;
  214.  
  215.    f = NULL ;
  216.    p = bufarr[GDGLF] ;
  217.    if (p) {
  218.       while (*p == ' ')
  219.          p++ ;
  220.       for (q = filename; *p > ' '; q++, p++)
  221.          *q = *p ;
  222.       *q = 0 ;
  223.       if (filename[0]!=0)
  224.          f = fopen(filename, "a") ;
  225.    }
  226.    return(f) ;
  227. }
  228. /*
  229.  *   This routine writes out additional information about the
  230.  *   blitter variables.
  231.  */
  232. static char *flags[] = { "LINE", "DESC", "FCI", "IFE", "EFE", "OVF", "SIGN" } ;
  233. logflagdata(f)
  234. FILE *f ;
  235. {
  236.    unsigned short t ;
  237.    unsigned short con0, con1 ;
  238.  
  239.    con0 = blitregs.con0 ;
  240.    con1 = blitregs.con1 ;
  241.    fprintf(f, "ASH = %d BSH = %d ", con0 >> 12, con1 >> 12) ;
  242.    if (con0 & SRCA)
  243.       fprintf(f, "SRCA ") ;
  244.    if (con0 & SRCB)
  245.       fprintf(f, "SRCB ") ;
  246.    if (con0 & SRCC)
  247.       fprintf(f, "SRCC ") ;
  248.    if (con0 & DEST)
  249.       fprintf(f, "DEST ") ;
  250.    fprintf(f, "\nFunction = %d (%s)\nFlags:  ", con0 & 255, bufarr[GDGFUNC]) ;
  251.    for (t=0; t<7; t++)
  252.       if (con1 & (1 << t))
  253.          fprintf(f, "%s ", flags[t]) ;
  254.    fprintf(f, "\n") ;
  255. }
  256.